import "package:ct_pa_majordomo/config/theme_vars.dart";
import "package:ct_pa_majordomo/pages/device/lock/api.dart";
import "package:ct_pa_majordomo/pages/device/lock/widgets/operation_record/index.dart";
import "package:ct_pa_majordomo/pages/widgets/menu_block.dart";
import "package:ct_pa_majordomo/router/keys.dart";
import "package:ct_pa_majordomo/utils/stacker.dart";
import "package:ct_pa_majordomo/widgets/normal_scaffold/index.dart";
import "package:flutter/cupertino.dart";
import "package:flutter/material.dart";
import "package:flutter_easyloading/flutter_easyloading.dart";

class UnlockRecord extends StatefulWidget {
  final int roomId;
  const UnlockRecord({super.key, required this.roomId});

  @override
  State<StatefulWidget> createState() => _UnlockRecordState();
  
}
class _UnlockRecordState extends State<UnlockRecord> {
  
  List _list = [];

  void _getLocks() async {
    EasyLoading.show();
    Map resData = await lockApi.lockByRoomList(widget.roomId);
    EasyLoading.dismiss();
    setState(() {
      _list = resData["data"] ?? [];
    });
  }

  @override
  void initState() {
    super.initState();
    _getLocks();
  }
  
  @override
  Widget build(BuildContext context) {
    return NormalScaffold(
      title: "开门记录",
      child: ListView.separated(
        padding: EdgeInsets.all(ThemeVars.paddingPage),
        itemBuilder: (context, index) {
          return MenuBlock(
            items: [
              MenuBlockItem(
                text: _list[index]["lockName"],
                showArrow: false,
                prefix: Container(
                  padding: EdgeInsets.all(6),
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.all(Radius.circular(100)),
                    border: Border.all(color: ThemeVars.colorPrimaryLight, width: 2)
                  ),
                  child: Icon(Icons.door_back_door_outlined),
                ),
                suffix: Icon(Icons.arrow_forward_ios, size: 20, color: ThemeVars.colorPrimary,),
                onTap: () {
                  Stacker.pushNamed(Keys.DEVICE_LOCK_OPERATION, arguments: {"lockId": _list[index]["lockId"], "lockData": _list[index]["lockData"]});
                }
              )
            ]
          );
        },
        separatorBuilder: (context, index) => const SizedBox(height: 12,),
        itemCount: _list.length
      ),
    );
  }
  
}